What's new

Help java

jazzL11

Addict
Joined
Aug 20, 2016
Posts
96
Reaction
17
Points
99
Age
26
Pa help ulit hehe

1. Write a program that reads in an integer and outputs a statement telling whether or not the
number is evenly divisible by three. If the number is not divisible by three the program should tell
that the number is not divisible by three and also output the remainder obtained when the number



2. Create a program that will output the factorial of 1 – N (where N is any number input from user
and N should not be greater than 15 and not less than 1)
Sample: Enter a number: 9
The factorial of 9 is 362880
Generation: 1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 = 362880
is divided by three.
 
Java:
import java.util.Scanner;
public class Main
{
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        problem1();
        problem2();
    }
    static void problem1(){
        System.out.print("Input: ");
        int input = sc.nextInt();
        if(input % 3 == 0)
            System.out.println("Input is divisible by 3");
       else
            System.out.println("Input is not divisible by 3, remainder: " + input % 3);
    }
    static void problem2(){
          System.out.print("Input: ");
          int input = sc.nextInt();
          if(input < 15 && input > 1){
              int sum = 1;
              for(int i = 2; i <= input; i++)
                  sum *= i;
               System.out.printf("The factorial of %d is %d", input, sum);
          }
          else
               System.out.println("Input out of range");
    }
}
 
yan, lods dami eh sakit na ulo ko
Screenshot_2021-03-18-19-19-46-79.jpg
 

Attachments

Worth it paba pagaralan ang java? Saka TS, ok lang magpatulong but mas ok kung mapractice mo. Lalo na pag ung pagsimplify ng codes.
 
[XX='alasacelui, c: 955347, m: 714257'][/XX] Oh, I see. Python na kasi mostly gamit sa mga companies I worked with. Lalo na at wala ng windows support Java.
 

Similar threads

Back
Top