Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views3 pages

Java Codes

Uploaded by

Naman Masodkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

Java Codes

Uploaded by

Naman Masodkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

package proj1;

import java.util.Scanner;
public class test{
public static void main (String[] args) {
int number1 = (int)(Math.random()*10);
if (number1>0.5) {
System.out.println("0");
}
else
{
System.out.println("1");
}
}
}

import java.util.Scanner;
2
3 public class GuessNumberOneTime {
4 public static void main(String[] args) {
5 // Generate a random number to be guessed
6 int number = (int)(Math.random() * 101);
7
8 Scanner input = new Scanner(System.in);
9 System.out.println("Guess a magic number between 0 and 100");
10
11 // Prompt the user to guess the number
12 System.out.print("\nEnter your guess: ");
13 int guess = input.nextInt();
14
15 if (guess == number)
16 System.out.println("Yes, the number is " + number);
17 else if (guess > number)
18 System.out.println("Your guess is too high");
19 else
20 System.out.println("Your guess is too low");
21 }
22 }

You might also like