๐Ÿ”’ Closed Help java

Status
Not open for further replies.

jazzL11

Enthusiast
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.webp
 
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.
 
Status
Not open for further replies.

About this Thread

  • 9
    Replies
  • 435
    Views
  • 6
    Participants
Last reply from:
MonkeyBabii

Online now

Members online
1,028
Guests online
989
Total visitors
2,017

Forum statistics

Threads
2,277,035
Posts
28,973,836
Members
1,229,694
Latest member
juannn_
Back
Top