- 4
import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println("enter y
Please explain me what error that may face by me
18 Antworten
+ 3
Thanks a lot
+ 2
package newone;
import java.util.*;
public class november29_2022_part3
public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n-sc.nextInt();
for (int i=1;i<11; i++); {
System.out.println (i*n); }
}
0
import java.util.Scanner;
public class Program
{
    public static void main(String[] args) {
	   Scanner read = new Scanner(System.in);
           int password;
0
import java.util.Scanner;  
public class SumOfNumbers2  
{  
public static void main(String args[])  
{  
int x, y, sum;  
Scanner sc = new Scanner(System.in);  
System.out.print("Enter the first number: ");  
x = sc.nextInt();  
System.out.print("Enter the second number: ");  
y = sc.nextInt();  
sum = sum(x, y);  
System.out.println("The sum of two numbers x and y is: " + sum);  
}  
//method that calculates the sum  
public static int sum(int a, int b)  
{  
int sum = a + b;  
return sum;  
}  
}  
Is this correct or not please explain me errors
0
I have a problem in my code can any one help me to slove it
0
import  java.util.Scanner;
public class Program {
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int temp = sc.nextlnt();
        
        if(temp <=100) {
        System.out.println("Boiling");
        
        } else {
        System.out.println("Not boiling");
        }
    }
}
0
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    int cash=sc.nextInt();
    if (cash < 10) {
        /* code */
        System.out.println("you donn't have enough money");
        System.out.println("get more money");
    }
    else if (cash>10 && cash<50) {
        System.out.println("you can get onething");
    }
    else{
        System.out.println("you can buy both");
    }
  
  }
}
Please explain where is error...
0
// DebugFive4.java
// Outputs highest of four numbers
import java.util.*;
public class DebugFive4
{
   public static void main (String args[]) 
   {
      Scanner input = new Scanner(System.in);
      int one, two, three, four;
      String str, output;
      System.out.println("Enter an integer");
      str = input.next();
      one = Integer.parseInt(str);
      System.out.println("Enter an integer");
      str = input.next();
      two = Integer.parseInt(str);
      System.out.println("Enter an integer");
      str = input.next();
      three = Integer.parseInt(str);
      System.out.println("Enter an integer");
      str = input.next();
      four = Integer.parseInt(str);
      if(one > two > one > three > one > four)
         output = "Highest is " + four;
      else
         if(two > one && two > three !! two > four)
            output = "Highest is " + three;
         else
           if(three > one && three > two && three > four)
              output = "Highest is " + three;
           else
              output = "Highest is " + four;
      System.out.println(output);
   }
}
0
import  java.util.Scanner;
public class Program {
    public static void main(String[] args) {
        //
0
public class MyClass {
    public static void main(String args[]) {
      int x=0;int y=1;int c;
      int z;
      Scanner sc=new Scanner(System.in);
      int n=sc.nextInt();
      System.out.print("enter the value n:" +n);
      
      for(int i=2;i<=n;i++)
      {
          c=x+y;
          System.out.print(c+" ");
           x=y;
           y=c;
      }
     
      
    }
}
0
import java.util.Scanner;
public class PhoneSystem {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PhoneBook phoneBook = new PhoneBook();
        while (true) {
            System.out.println("أدخل الخيار المطلوب:");
            System.out.println("1. إضافة اسم ورقم هاتف");
            System.out.println("2. البحث عن اسم");
            System.out.println("3. طباعة دليل الهاتف");
            System.out.println("4. الخروج");
            int choice = scanner.nextInt();
            scanner.nextLine(); // لتجاوز المشكلة التي تحدثها nextInt()
            switch (choice) {
                case 1:
                    System.out.println("أدخل الاسم:");
                    String name = scanner.nextLine();
                    System.out.println("أدخل رقم الهاتف:");
                    String phoneNumber = scanner.nextLine();
                    phoneBook.addContact(name, phoneNumber);
                    break;
                case 2:
                    System.out.println("أدخل الاسم للبحث عنه:");
                    String searchName = scanner.nextLine();
                    String result = phoneBook.searchContact(searchName);
                    System.out.println(result != null ? "رقم الهاتف: " + result : "الاسم غير موجود في دليل الهاتف");
                    break;
                case 3:
                    phoneBook.printPhoneBook();
                    break;
                case 4:
                    System.out.println("تم الخروج من النظام.");
                    System.exit(0);
                default:
                    System.out.println("الرجاء اختيار خيار صحيح.");
            }
        }
    }
}
class PhoneBook {
    private final Map<String, String> contacts;
    public PhoneBook() {
        contacts = new HashMap<>();
    }
    public void addContact(String name, String phoneNumber) {
        contacts.put(name, phoneNumber);
        System.out.println("تمت إضافة " + name + " إلى دليل الهاتف.");
    }
    public String searchContact(String na
0
My answer ✅
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);
        int num1 = read.nextInt();
        int num2 = read.nextInt();
        // Calculate num1 raised to the power of num2
        double result = Math.pow(num1, num2);
        // Print the result
        System.out.println(result);
        read.close();
    }
}
0
Everything is Right 
0
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
       
       Scanner scanner = new Scanner(System.in);
       int price = scanner.nextInt();
       //complete the code
       
     
   }
}
0
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
       
       Scanner scanner = new Scanner(System.in);
       int price = scanner.nextInt();
       //complete the code
       
     
   }
}
0
import java.util.Scanner;
import java.util.Random;
public class RunningGame {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int playerPosition = 0;
        int obstaclePosition = 50;
        int score = 0;
        boolean isRunning = true;
        System.out.println("Welcome to the Running Game!");
        System.out.println("Press 'r' to run and avoid the obstacle.");
        System.out.println("Type 'exit' to quit the game.");
        while (isRunning) {
            // Game progress
            if (playerPosition == obstaclePosition) {
                System.out.println("Oh no! You hit an obstacle. Game over!");
                System.out.println("Your score: " + score);
                break;
            }
            // Move the obstacle closer to the player
            obstaclePosition--;
            if (obstaclePosition < 0) {
                obstaclePosition = 50;
                score++;
            }
            // Show the current game state
            displayGameState(playerPosition, obstaclePosition, score);
            // Get player input
            System.out.print("Your move: ");
            String input = scanner.nextLine();
            // Quit if player types 'exit'
            if (input.equalsIgnoreCase("exit")) {
                System.out.println("You quit the game. Your final score: " + score);
                break;
            }
            // Player attempts to run (jump)
            if (input.equalsIgnoreCase("r")) {
                playerPosition = 1;  // Jumping position (can vary the jump logic)
                System.out.println("You are running!");
            } else {
                playerPosition = 0;  // Default position
            }
            // Delay for game loop
            try {
                Thread.sleep(500);  // Half a second delay for game pace
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        s
0
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
       
       Scanner scanner = new Scanner(System.in);
       int price = scanner.nextInt();
       //complete the code
       if (price > 1000) {
           System.out.println("Discounted price: " + (price * 0.9));
       } else {
           System.out.println("Original price: " + price);
       }
     
   }
}



